"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_consultation_index = require("../../../api/consultation/index.js");
const config_app = require("../../../config/app.js");
const utils_tools = require("../../../utils/tools.js");
const stores_userInfo = require("../../../stores/userInfo.js");
if (!Array) {
  const _easycom_up_album2 = common_vendor.resolveComponent("up-album");
  const _easycom_up_gap2 = common_vendor.resolveComponent("up-gap");
  const _easycom_up_list_item2 = common_vendor.resolveComponent("up-list-item");
  const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  const _easycom_up_list2 = common_vendor.resolveComponent("up-list");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_album2 + _easycom_up_gap2 + _easycom_up_list_item2 + _easycom_up_empty2 + _easycom_up_list2 + _easycom_up_toast2)();
}
const _easycom_up_album = () => "../../../node-modules/uview-plus/components/u-album/u-album.js";
const _easycom_up_gap = () => "../../../node-modules/uview-plus/components/u-gap/u-gap.js";
const _easycom_up_list_item = () => "../../../node-modules/uview-plus/components/u-list-item/u-list-item.js";
const _easycom_up_empty = () => "../../../node-modules/uview-plus/components/u-empty/u-empty.js";
const _easycom_up_list = () => "../../../node-modules/uview-plus/components/u-list/u-list.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_album + _easycom_up_gap + _easycom_up_list_item + _easycom_up_empty + _easycom_up_list + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const data = common_vendor.reactive({
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        policeUserId: userInfoStore.userInfo.userId
      },
      list: [],
      total: 0
    });
    const { queryParam, list, total } = common_vendor.toRefs(data);
    const getConsultationList = () => {
      common_vendor.index.showLoading({
        title: "加载中",
        mask: true
      });
      api_consultation_index.listPagePolice(queryParam.value).then((res) => {
        common_vendor.index.hideLoading();
        const { data: data2 } = res;
        data2.records = data2.records ?? [];
        data2.records = processImg(data2.records);
        list.value = [...list.value, ...data2.records];
        total.value = data2.total;
      }).catch((err) => {
        common_vendor.index.hideLoading();
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const processImg = (arr) => {
      if (arr.length) {
        arr = arr.map((item) => {
          if (item.imgUrl) {
            item.imgUrl = item.imgUrl.split(",");
            if (item.imgUrl.length) {
              item.imgUrl = item.imgUrl.map((img) => {
                img = config_app.imgPrefix + img;
                return img;
              });
            }
          }
          return item;
        });
      }
      return arr;
    };
    const updateStatus = (id, handleStatus) => {
      api_consultation_index.updateHandleStatus({
        handleStatus,
        id
      }).then((res) => {
        uToastRef.value.show({
          type: "success",
          message: "状态设置成功"
        });
        queryParam.value.pageNum = 1;
        list.value = [];
        total.value = 0;
        getConsultationList();
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    common_vendor.onLoad(() => {
      getConsultationList();
    });
    const scrolltolower = () => {
      let allTotal = queryParam.value.pageNum * queryParam.value.pageSize;
      if (allTotal >= total.value) {
        return;
      }
      queryParam.value.pageNum = ++queryParam.value.pageNum;
      getConsultationList();
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(list).length
      }, common_vendor.unref(list).length ? {
        b: common_vendor.f(common_vendor.unref(list), (item, index, i0) => {
          return common_vendor.e({
            a: common_vendor.t(item.content),
            b: item.imgUrl && item.imgUrl.length
          }, item.imgUrl && item.imgUrl.length ? {
            c: "65bfa37f-2-" + i0 + "," + ("65bfa37f-1-" + i0),
            d: common_vendor.p({
              urls: item.imgUrl,
              space: "20rpx",
              singleSize: "155rpx",
              multipleSize: "155rpx",
              autoWrap: true,
              maxCount: 3,
              unit: "rpx"
            })
          } : {}, {
            e: common_vendor.t(item.consultUserName),
            f: common_vendor.t(item.phonenumber),
            g: common_vendor.o(($event) => common_vendor.unref(utils_tools.callPhone)(item.phonenumber), index),
            h: common_vendor.t(item.address),
            i: common_vendor.t(item.createTime ? common_vendor.unref(common_vendor.dayjs)(item.createTime).format("YYYY-MM-DD hh:mm:ss") : ""),
            j: item.handleStatus === 0
          }, item.handleStatus === 0 ? {
            k: common_vendor.o(($event) => updateStatus(item.id, 1), index)
          } : common_vendor.e({
            l: item.handleStatus == 1
          }, item.handleStatus == 1 ? {} : {}), {
            m: index + 1 != common_vendor.unref(list).length
          }, index + 1 != common_vendor.unref(list).length ? {
            n: "65bfa37f-3-" + i0 + "," + ("65bfa37f-1-" + i0),
            o: common_vendor.p({
              height: "10"
            })
          } : {}, {
            p: index,
            q: "65bfa37f-1-" + i0 + ",65bfa37f-0"
          });
        })
      } : {
        c: common_vendor.p({
          mode: "data",
          text: "暂无记录",
          icon: "http://cdn.uviewui.com/uview/empty/data.png"
        })
      }, {
        d: common_vendor.o(scrolltolower),
        e: common_vendor.p({
          height: "100vh"
        }),
        f: common_vendor.sr(uToastRef, "65bfa37f-5", {
          "k": "uToastRef"
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-65bfa37f"]]);
wx.createPage(MiniProgramPage);
